package com.hm.PushCaseService.control;

import com.hm.PushCaseService.framework.service.base.IBaseService;
import com.hm.PushCaseService.pojo.response.CaptchaResponse;
import com.hm.PushCaseService.service.captcha.ICaptchaService;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;


@RestController
@RequestMapping(value = "/main", produces = {"application/json;charset=UTF-8"})
public class PCS_000_000_001<T> {

    private static final Logger logger = LoggerFactory.getLogger(PCS_000_000_001.class);

    private final IBaseService<CaptchaResponse> iBaseService;

    private final ICaptchaService iCaptchaService;

    public PCS_000_000_001(IBaseService<CaptchaResponse> iBaseService, ICaptchaService iCaptchaService) {
        this.iBaseService = iBaseService;
        this.iCaptchaService = iCaptchaService;
    }

    //验证码
    @PostMapping(value = "/000_000_001")
    public String doPost(HttpServletRequest request) {
        //基本处理
        HashMap<String, String> resMap = iBaseService.handleRequest(request);
        String state = resMap.get("state");
        String msg = resMap.get("msg");
        String secretKey = resMap.get("secretKey");
        if (!state.equals("000")) {
            return iBaseService.generateFail(msg);
        }
        CaptchaResponse captcha = iCaptchaService.getCaptcha();
        return iBaseService.generateSucceed(secretKey, captcha);
    }

}
